﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace LSUtility
{
    public class LogTool
    {
        #region 写入文本日志
        /// <summary>
        /// 写入文本日志
        /// </summary>
        /// <param name="description">日志</param>
        [MethodImpl(MethodImplOptions.Synchronized)]
        public static void WriteEntry(string description)
        {
            WriteEntry(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + DateTime.Today.ToString("yyyy'-'MM'-'dd") + "_EventLog.txt", DateTime.Now.ToString("yyyy'-'MM'-'dd HH:mm:ss   ---  ") + description);
        }

        /// <summary>
        /// 写入文本日志（扩展）
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="description"></param>
        [MethodImpl(MethodImplOptions.Synchronized)]
        public static void WriteEntry(string filePath, string description)
        {
            try
            {
                File.AppendAllText(filePath, description + "\r\n");
            }
            finally
            {
            }
        }
        #endregion

        #region 创建文件目录
        /// <summary>
        /// 创建文件目录
        /// </summary>
        /// <param name="folderPath"></param>
        public static void CreateFolder(string folderPath)
        {
            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }
        }
        #endregion
    }
}
